package com.cn.demo4.util;

import com.alibaba.fastjson.JSONObject;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 图片上传
 */
@WebServlet("/loadImg/img")
public class WangEdit extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1.乱码
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        //2.取得前台的值
        LoadImg.loadImg(req);

        //返回数据
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("url",req.getAttribute("img"));
        resp.getWriter().println(jsonObject);


    }
}
